home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AppsToGo / DTS.StyleChat / WindowDialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  9.0 KB  |  386 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        WindowDialog.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19.  
  20.  
  21. /*****************************************************************************/
  22.  
  23.  
  24.  
  25. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  26. #include "App.defs.h"        /* Get various application definitions.            */
  27. #include "App.protos.h"        /* Get the prototypes for application.            */
  28.  
  29. #ifndef __ERRORS__
  30. #include <Errors.h>
  31. #endif
  32.  
  33. #ifndef __UTILITIES__
  34. #include "Utilities.h"
  35. #endif
  36.  
  37.  
  38.  
  39. /*****************************************************************************/
  40.  
  41.  
  42.  
  43. extern RgnHandle    gCursorRgn;                /* We handle cursors here, so we need */
  44. extern CursPtr        gCursorPtr;                /* to know about these things. */
  45.                                             /* Above are DTS.Lib..framework globals. */
  46.  
  47. extern short        gDialogErr;                /* Error numbers to be displayed in   */
  48.                                             /* a dialog window of type 'ERR#' are */
  49.                                             /* passed in this way.                  */
  50.  
  51. static short    gCtlNum;
  52.  
  53.  
  54.  
  55. /*****************************************************************************/
  56. /*****************************************************************************/
  57.  
  58. #ifdef applec
  59. #pragma segment WindowDialog
  60. #endif
  61.  
  62. /*****************************************************************************/
  63. /*****************************************************************************/
  64.  
  65.  
  66.  
  67. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  68. /* See CalcFrameRgn() for info. */
  69.  
  70. void    DialogCalcFrameRgn(FileRecHndl frHndl, WindowPtr window, RgnHandle rgn)
  71. {
  72. #ifndef __MWERKS__
  73. #pragma unused (frHndl, window, rgn)
  74. #endif
  75. }
  76.  
  77.  
  78.  
  79. /*****************************************************************************/
  80.  
  81.  
  82.  
  83. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  84. /* See ContentClick() for info. */
  85.  
  86. void    DialogContentClick(WindowPtr window, EventRecord *event, Boolean firstClick)
  87. {
  88. #ifndef __MWERKS__
  89. #pragma unused (firstClick)
  90. #endif
  91.  
  92.     short            cnum, action;
  93.     ControlHandle    ctl;
  94.  
  95.     gCtlNum = cnum = IsCtlEvent(window, event, &ctl, &action);
  96.     if ((cnum == -1) || (cnum == -2))
  97.         if (GetButtonVariant(ctl) == pushButProc)
  98.             DisposeOneWindow(window, kClose);
  99.  
  100.     return;
  101. }
  102.  
  103.  
  104.  
  105. /*****************************************************************************/
  106.  
  107.  
  108.  
  109. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  110. /* See ContentKey() for info. */
  111.  
  112. Boolean    DialogContentKey(WindowPtr window, EventRecord *event, Boolean *passThrough)
  113. {
  114. #ifndef __MWERKS__
  115. #pragma unused (passThrough)
  116. #endif
  117.  
  118.     short            cnum, action;
  119.     ControlHandle    ctl;
  120.  
  121.     gCtlNum = cnum = IsCtlEvent(window, event, &ctl, &action);
  122.     if ((cnum == -1) || (cnum == -2)) {
  123.         if (GetButtonVariant(ctl) == pushButProc) {
  124.             DisposeOneWindow(window, kClose);
  125.             return(true);
  126.         }
  127.     }
  128.  
  129. #if DEV_VERSION
  130.     if ((event->message & charCodeMask) == (unsigned char)'≥') {
  131.         if ((event->modifiers & (optionKey | cmdKey)) == (optionKey | cmdKey)) {
  132.             gCtlNum = -2;
  133.             DisposeOneWindow(window, kClose);
  134.         }
  135.     }
  136. #endif
  137.  
  138.     return(true);
  139. }
  140.  
  141.  
  142.  
  143. /*****************************************************************************/
  144.  
  145.  
  146.  
  147. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  148. /* See DrawFrame() for info. */
  149.  
  150. void    DialogDrawFrame(FileRecHndl frHndl, WindowPtr window, Boolean activate)
  151. {
  152.     MoveTo(0, (*frHndl)->fileState.topSidebar - 1);
  153.     LineTo((*frHndl)->fileState.leftSidebar - 1 - 16384, (*frHndl)->fileState.topSidebar - 1);
  154.     LineTo((*frHndl)->fileState.leftSidebar - 1 - 16384, 16383);
  155.  
  156.     BeginFrame(window);
  157.     DoDrawControls(window, activate);
  158.     EndFrame(window);
  159. }
  160.  
  161.  
  162.  
  163. /*****************************************************************************/
  164.  
  165.  
  166.  
  167. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  168. /* See FreeDocument() for info. */
  169.  
  170. OSErr    DialogFreeDocument(FileRecHndl frHndl)
  171. {
  172.     return(DefaultFreeDocument(frHndl));
  173. }
  174.  
  175.  
  176.  
  177. /*****************************************************************************/
  178.  
  179.  
  180.  
  181. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  182. /* See FreeWindow() for info. */
  183.  
  184. OSErr    DialogFreeWindow(FileRecHndl frHndl, WindowPtr window)
  185. {
  186. #ifndef __MWERKS__
  187. #pragma unused (frHndl, window)
  188. #endif
  189.  
  190. /* For dialogs that need to keep their info before getting dismissed:
  191. **   Check gCtlNum to see what control caused dialog dismissal.
  192. **     -1: Default button.
  193. **     -2: Cancel button.
  194. **   If you determine that the dialog shouldn't be dismissed after all, then
  195. **   return an error.
  196. */
  197.  
  198.     return(noErr);
  199. }
  200.  
  201.  
  202.  
  203. /*****************************************************************************/
  204.  
  205.  
  206.  
  207. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  208. /* See ImageDocument() for info. */
  209.  
  210. OSErr    DialogImageDocument(FileRecHndl frHndl)
  211. {
  212. #ifndef __MWERKS__
  213. #pragma unused (frHndl)
  214. #endif
  215.  
  216.     WindowPtr    curPort;
  217.  
  218.     GetPort(&curPort);
  219.     DoDrawControls(curPort, false);            /* Draw the content controls. */
  220.  
  221.     return(noErr);
  222. }
  223.  
  224.  
  225.  
  226. /*****************************************************************************/
  227.  
  228.  
  229.  
  230. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  231. /* See InitContent() for info. */
  232.  
  233. OSErr    DialogInitContent(FileRecHndl frHndl, WindowPtr window)
  234. {
  235.     OSErr            err;
  236.     OSType            sftype;
  237.     ControlHandle    ctl;
  238.     Str255            pstr;
  239.  
  240.     sftype = (*frHndl)->fileState.sfType;
  241.     err = AddControlSet(window, sftype, kwStandardVis, 0, 0, nil);
  242.     if (sftype == 'ERR#') {
  243.         CNum2Ctl(window, 100, &ctl);
  244.         if (ctl) {
  245.             CTEGetPStr(ctl, pstr);
  246.             pcatdec(pstr, gDialogErr);
  247.             gDialogErr = noErr;
  248.             CTESetPStr(ctl, pstr);
  249.         }
  250.     }
  251.  
  252.     return(err);
  253. }
  254.  
  255.  
  256.  
  257. /*****************************************************************************/
  258.  
  259.  
  260.  
  261. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  262. /* See ResizeContent() for info. */
  263.  
  264. void    DialogResizeContent(WindowPtr window, short oldh, short oldv)
  265. {
  266. #ifndef __MWERKS__
  267. #pragma unused (window, oldh, oldv)
  268. #endif
  269. }
  270.  
  271.  
  272.  
  273. /*****************************************************************************/
  274.  
  275.  
  276.  
  277. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  278. /* See ScrollFrame() for info. */
  279.  
  280. void    DialogScrollFrame(FileRecHndl frHndl, WindowPtr window, long dh, long dv)
  281. {
  282. #ifndef __MWERKS__
  283. #pragma unused (frHndl, window, dh, dv)
  284. #endif
  285. }
  286.  
  287.  
  288.  
  289. /*****************************************************************************/
  290.  
  291.  
  292.  
  293. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  294. /* See UndoFixup() for info. */
  295.  
  296. void    DialogUndoFixup(FileRecHndl frHndl, Point contOrg, Boolean afterUndo)
  297. {
  298. #ifndef __MWERKS__
  299. #pragma unused (frHndl, contOrg, afterUndo)
  300. #endif
  301.  
  302.     /* See DTS.Draw for an example of what you might do here. */
  303. }
  304.  
  305.  
  306.  
  307. /*****************************************************************************/
  308.  
  309.  
  310.  
  311. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  312. /* See WindowCursor() for info. */
  313.  
  314. Boolean    DialogWindowCursor(FileRecHndl frHndl, WindowPtr window, Point globalPt)
  315. {
  316. #ifndef __MWERKS__
  317. #pragma unused (frHndl, window, globalPt)
  318. #endif
  319.  
  320.     /* For examples of applications that have non-arrow cursor regions,
  321.     ** see DTS.Chat and DTS.Draw. */
  322.  
  323.     DoSetCursor(&qd.arrow);
  324.     return(true);
  325. }
  326.  
  327.  
  328.  
  329. /*****************************************************************************/
  330.  
  331.  
  332.  
  333. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  334. /* See WindowGoneFixup() for info. */
  335.  
  336. void    DialogWindowGoneFixup(WindowPtr window)
  337. {
  338. #ifndef __MWERKS__
  339. #pragma unused (window)
  340. #endif
  341. }
  342.  
  343.  
  344.  
  345. /*****************************************************************************/
  346. /*****************************************************************************/
  347. /*****************************************************************************/
  348.  
  349.  
  350.  
  351. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  352. /* See AdjustMenuItems() for info. */
  353.  
  354. Boolean    DialogAdjustMenuItems(WindowPtr window, short menuID)
  355. {
  356. #ifndef __MWERKS__
  357. #pragma unused (window)
  358. #endif
  359.  
  360.     if (menuID == mEdit)
  361.         CTEEditMenu(nil, mEdit, UnmapMItem(mEdit, kStdUndo), UnmapMItem(mEdit, kStdCut));
  362.  
  363.     return(false);
  364. }
  365.  
  366.  
  367.  
  368. /*****************************************************************************/
  369.  
  370.  
  371.  
  372. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  373. /* See DoMenuItem() for info. */
  374.  
  375. Boolean    DialogDoMenuItem(WindowPtr window, short menuID, short menuItem)
  376. {
  377. #ifndef __MWERKS__
  378. #pragma unused (window)
  379. #endif
  380.  
  381.     return(DoMenuCommand(menuID, menuItem));
  382. }
  383.  
  384.  
  385.  
  386.